<?
include_once "index.php";
?>
<style type="text/css" >
table.data {
  background-color:#fff;
   color:#213243;
}
.data th {background-color:gray; color:#ffffff}
.pagingDiv {width:800px; height:20px}
.pNo {float:left; width:10px; margin-left:3px; margin-right:3px; border:0px solid gray;}
.pNo a {text-decoration:none;}
</style>

<?
//-------------------------------PAGING--------------------------------------------

// Number of records to show per page
$recordsPerPage = 2;  # 0

// default startup page
$pageNum = 1;

if(isset($_GET['p'])) {
  $pageNum = $_GET['p'];
  settype($pageNum, 'integer');
}

$offset = ($pageNum - 1) * $recordsPerPage;
//-------------------------------PAGING--------------------------------------------------

	$ename1 = $_GET['ename'];
	$day = date(d);
	$month = date(m);
	$year = date(Y);
		
	$del = "delete from job_post where EXday = \"$day\" and EXmonth = \"$month\" and EXyear = \"$year\" ";
	$rdel = mysql_query($del) or die(mysql_error());

if(!empty($job_del))
{
	$q1 = "delete from job_post where job_id = \"$job_del\" and ename = \"$ename1\" ";
	$r1 = mysql_query($q1) or die(mysql_error());

	echo "<br><br><br><center><span class=HeaderClass>The selected job offer was deleted successfull.</span></center>";
}
else
{
$qm = "select * from job_post where ename = \"$ename1\" order by job_id LIMIT $offset, $recordsPerPage";
$rqm = mysql_query($qm) or die(mysql_error());

	if(mysql_num_rows($rqm) > '0')
	{
		echo "<br><center><font size=3>Your current job offers</font></center>";
			while($aqm = mysql_fetch_assoc($rqm))
		{
		echo "
		<br><table align=center border=1 bordercolor=993300 cellspacing=0 width=550>
					<tr>
						<td>
							<table border=0 align=center width=530>
					";
	

		$day = date(d);
		$month = date(m);
		$year = date(Y);

		$EXdate = "$aqm[EXyear]"."-"."$aqm[EXmonth]"."-"."$aqm[EXday]";
		$dnes = "$year"."-"."$month"."-"."$day";

		$qd = "select to_days('$EXdate') - to_days('$dnes')";
		$rqd = mysql_query($qd) or die(mysql_error());
		$adate = mysql_fetch_array($rqd);

		$qempl = "select CompanyName, CompanyCountry, CompanyCity from job_employer_info where ename = \"$_SESSION[ename]\" ";
		$rempl = mysql_query($qempl) or die(mysql_error());
		$ae = mysql_fetch_array($rempl);

			if($aqm[j_target]  == '1')
			{
				$clname = 'Student (High School)';
			}
			elseif($aqm[j_target]  == '2')
			{
				$clname = 'Student (undergraduate/graduate)';
			}
			elseif($aqm[j_target]  == '3')
			{
				$clname = 'Entry Level (less than 2 years of experience)';
			}
			elseif($aqm[j_target]  == '4')
			{
				$clname = 'Mid Career (2+ years of experience)';
			}
			elseif($aqm[j_target]  == '5')
			{
				$clname = 'Management (Manager/Director of Staff)';
			}
			elseif($aqm[j_target]  == '6')
			{
				$clname = 'Executive (SVP, EVP, VP)';
			}
			elseif($aqm[j_target] == '7')
			{
				$clname = 'Senior Executive (President, CEO)';
			}

		$show_category = str_replace("|", ", ", $aqm[JobCategory]);
		$show_description = nl2br($aqm[short_desc]);
		$show_respon1 = nl2br($aqm[responsibilities]);
		$show_require1 = nl2br($aqm[requirements]);

		$show_respon = str_replace("<br />", "<br />*", $show_respon1);
		$show_require = str_replace("<br />", "<br />*", $show_require1);
		
		echo "<tr>
		<td class=BlackText>
		<b>Position:</b> $aqm[position]  <br><br> 
		<b>Short Deascription: </b><br>$show_description<br><br>
		<b>Responsibilities: </b><br>* $show_respon<br><br>
		<b>Requirements: </b><br>* $show_require<br><br>
		<b>Salary: </b> $aqm[salary] / $aqm[s_period]<br><br>
		<b>Job category: </b> $show_category <br><br>
		<b>Target: </b> $clname <br><br>
		<b>The job expire after: </b> $adate[0] day(s)<br><br>
		<b>Country:</b> $aqm[CompanyCountry]<br><br>
		view <a href=\"ManageAplicants.php?job_id=$aqm[job_id]&job_id=$aqm[job_id]&position=$aqm[position]\" class=TNA> aplicants list</a> for this position
		
		</td>
		<td valign=top align=right width=100>
		<a href=AEO.php?job_id=$aqm[job_id] class=GreenLink>Edit</a> | <a href=\"ADO.php?job_id=$aqm[job_id]\" class=TNA OnClick=\"return cdel('job offer');\">Delete</a>
		</td>
		</tr>
		";
		echo "
					</table>
				</td>
			</tr>
		</table>";
		}

//-----------------------------------------PAGING-------------------------------------------
		
	# Update this query with same where clause you are using above.
  $query   = "SELECT COUNT(job_id) AS dt FROM job_post WHERE ename = '$ename1'"; # 3

  $result  = mysql_query($query) or die('Mysql Err. 2');
  $row     = mysql_fetch_assoc($result);
  $numrows = $row['dt'];  # 4

  $maxPage = ceil($numrows/$recordsPerPage);

  $nav = '';
  for($page = 1; $page <= $maxPage; $page++)
  {
       if ($page == $pageNum)
       {
            $nav .= "<div class=\"pNo\">$page</div>";
       }
      else
       {
            $nav .= "<div class=\"pNo\"><a href=\"?p=$page&ename=$ename1\">$page</a></div>";
       }
  }

  if ($pageNum > 1)  {

       $page = $pageNum - 1;
       $prev = "<a href=\"?p=$page&ename=$ename1\"><strong>Prev</strong></a>";

       $first = "<a href=\"?p=1&ename=$ename1\"><strong>First</strong></a>";
  }
  else {
       $prev  = '<strong>  </strong>';
       $first = '<strong>   </strong>';
  }

  if ($pageNum < $maxPage) {
       $page = $pageNum + 1;
       $next = "<a href=\"?p=$page&ename=$ename1\"><strong>Next</strong></a>";

       $last = "<a href=\"?p=$maxPage&ename=$ename1\"><strong>Last</strong></a>";
  }
  else {
       $next = '<strong>  </strong>';
       $last = '<strong>   </strong>';
  }
  
  echo "<table border=0 align=right  cellspacing=0 cellpadding=0 style=\"margin-right: 20px\">
  				<tr>
  				<td>$first</td>
  				<td>$prev</td>
  				<td>$nav</td>
  				<td>$next</td>
  				<td>$last</td>
  			</table>";
//---------------------------------------PAGING----------------------------------------
	
	}
	else
	{
		echo "<center><span class=\"BlackLink\">Click <a href=\"PostJob.php\" class=TNA>here</a> to post your first job offer!</span>";
	}

}
?>
<? include_once('../footer.php'); ?>